﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GuessNumber
{
    /// <summary>
    /// 游戏设计类
    /// </summary>
    public class Game
    {
        private int key;// 正确答案
        private int count=0; // 统计次数
        private int numArrange = 2;//游戏难度

        public int NumArrange
        {
            get { return numArrange; }
        }
public int Count
{
  get { return count; }
  set { count = value; }
}
      
        /// <summary>
        /// 获取游戏开始的说明文本
        /// </summary>
        /// <returns></returns>
        internal string getStartText()
        {
            string str = string.Empty;
            str = "本程序是一个猜数字的小游戏。\n数字的范围有:\na 0- 10 (难度1)\nb 0-100（难度2）\nc 0-200（难度3）\n";
            str += "数字的范围默认是0-100（难度2）\n输入GDC可以换难度。\n";
            str += "输入Q或q退出。\n请输入想要猜测的数字：";
            return str;
        }
        /// <summary>
        /// 每次的结果
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        internal string getResult(string val)
        {
            int n = 0;
            try
            {
               n = Int32.Parse(val);//输入值
            }
            catch (Exception e)
            {
                return e.Message+"\n请重新输入！";
            }
           
            string returnVal=string.Empty;//返回值
            int a=0;//判断值
            if (numArrange==1)
            {
                if(key>n)
                {
                    a = 2;
                }
                else if(key<n)
                {
                    a = 3;
                }
                else
                {
                    a=1;
                }
            }
            else
            {
                if (key > n)
                {
                    int b = key - n;
                    if (b < 5)
                    { a = 4; }
                    else if (b >= 5 && b <= 20)
                    { a = 5; }
                    else
                    { a = 6; }

                }
                else if (key < n)
                {
                    int b = n - key;
                    if (b < 5)
                    { a = 7; }
                    else if (b >= 5 && b <= 20)
                    { a = 8; }
                    else
                    { a = 9; }
                }
                else
                {
                    a = 1;
                   
                }
            }
            switch (a)
            {
                case 1: returnVal = "Congratulations！你猜对了！^_^"; break;
                case 2: returnVal = "小了哦 ^_^";  break;
                case 3: returnVal = "大了哦 ^_^";  break;
                case 4: returnVal = "小了！和正确答案很接近了哦，再猜一次吧！ ^_^"; break;
                case 5: returnVal = "小了！和正确答案比较接近了，再猜一次吧！^_^";  break;
                case 6: returnVal = "小了！和正确答案差得很远，再猜一次吧！^_^";   break;
                case 7: returnVal = "大了！和正确答案很接近了哦，再猜一次吧！ ^_^";break;
                case 8: returnVal = "大了！和正确答案比较接近了，再猜一次吧！^_^";break;
                case 9: returnVal = "大了！和正确答案差得很远，再猜一次吧！^_^"; break;
            }
            return returnVal;
        }
        
        /// <summary>
        /// 对猜数次数进行评价
        /// </summary>
        /// <returns></returns>
        internal string getLevel()
        {
            string returnVal=string.Empty;
            if(numArrange==1)
            {
                if (count == 1)
                { returnVal = "你很幸运哦！"; }
                else
                { returnVal = "还好"; }
            }
            else
            {
                if(count==1)
                { returnVal = "我想你可以去买一张彩票了，太幸运了！"; }
                else if(count<=5 && count>1)
                { returnVal = "运气也很不错噢！"; }
                else if (count>5 && count<=20)
                {returnVal="还好啦，很一般的运气！";}
                else if(count>20 && count<50)
                { returnVal = "运气不太好哦！"; }
                else
                { returnVal = "真是糟糕透顶的运气！"; }
            }
            return returnVal;
        }
        /// <summary>
        /// 根据输入的1，2，3生成1-10，1-100，1-200范围内的随机数作为答案
        /// </summary>
        /// <param name="numArrange"></param>
        /// <returns></returns>
        internal void getRandom()
        {
            Random ran = new Random();
            switch (numArrange)
            {
                case 1:
                    key =Convert.ToInt32(ran.NextDouble()*10);
                    break;
                case 2:
                    key = Convert.ToInt32(ran.NextDouble() * 100);
                    break;
                case 3:
                    key = Convert.ToInt32(ran.NextDouble() * 200);
                    break;
            }
        }
        
        /// <summary>
        /// 是否需要帮助
        /// </summary>
        /// <param name="strVal"></param>
        /// <returns></returns>
        internal string getHelp()
        {
            return key.ToString();
        }
        
        /// <summary>
        /// 设置游戏难度
        /// </summary>
        /// <param name="strVal"></param>
        internal void setLevel(string strVal)
        {
            if (strVal == "a")
                numArrange = 1;
            else if (strVal == "b")
                numArrange = 2;
            else if (strVal == "c")
                numArrange = 3;
            else
            {
                numArrange = 2;
            }
        }
    }
}
